<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>博客正文</title>
    <link rel="stylesheet" href="css/conmmon.css">
    <link rel="stylesheet" href="css/blog_content.css">
    <link rel="stylesheet" href="editor.md/css/editormd.preview.min.css" />
    <script src="js/jquery.min.js"></script>
    <script src="js/jscommon.js"></script>
    <script src="editor.md/editormd.js"></script>
    <script src="editor.md/lib/marked.min.js"></script>
    <script src="editor.md/lib/prettify.min.js"></script>
</head>

<body>
    <!-- 导航栏 -->
    <div class="nav">
        <img src="img/小灰灰.jpeg" alt="">
        <span class="title">我的博客系统</span>
        <!-- 用来占据中间位置 -->
        <span class="spacer"></span>
        <a href="blog_list.html">主页</a>
        <a href="myblog_draft_list.html">我的草稿</a>
        <a href="blog_add.html">写博客</a>
        <a href="login.html">登陆</a>
        <a href="javascript:logout()">注销</a>
    </div>
    <!-- 版心 -->
    <div class="container">
        <!-- 左侧个人信息 -->
        <div class="container-left">
            <div class="card">
                <img src="img/智羊羊.jpeg" class="avtar" alt="">
                <h3 id="username"></h3>
                <a href="http:www.github.com">github 地址</a>
                <div class="counter">
                    <span>文章</span>
                    <span>分类</span>
                </div>
                <div class="counter">
                    <span id="artTotal"></span>
                    <span>1</span>
                </div>
            </div>
        </div>
        <!-- 右侧内容详情 -->
        <div class="container-right">
            <div class="blog-content">
                <!-- 博客标题 -->
                <h3 id="title">我的第一篇博客</h3>
                <!-- 博客时间 -->
                <div class="date">
                    最后一次修改：<span id="updatetime">2021-06-02</span> &nbsp;&nbsp;&nbsp;
                    发布时间：<span id="createtime">2021-06-02</span> &nbsp;&nbsp;&nbsp;
                    阅读量：<span id="rcount">2021-06-02</span>
                </div>
                <!-- 博客正文 -->
                <div id="editorDiv" style="opacity:80%">

                </div>
            </div>
        </div>
    </div>
    <script type="text/javascript">

        // 获取文章信息和用户信息
        function getArtDetail(id) {
            if(id == "") {
                alert("非法参数!");
                return;
            }
            jQuery.ajax({
                url: "/art/detail",
                type: "POST",
                data: {"id": id},
                success: function(result) {
                    if(result != null && result.code == 200) {
                        jQuery("#title").html(result.data.title);
                        jQuery("#updatetime").html(result.data.updatetime);
                        jQuery("#createtime").html(result.data.createtime);
                        jQuery("#rcount").html(result.data.rcount);
                        editormd.markdownToHTML("editorDiv", {
                            markdown: result.data.content
                        });
                        // 根据用户 id 获取用户信息
                        showUser(result.data.uid);
                    }else {
                        alert("获取文章失败，请刷新重试！");
                        return;
                    }
                }
            });
        }
        getArtDetail(getUrlValue("id"));

        // 将文章阅读量 + 1操作
        function addRcount() {
            var id = getUrlValue("id");
            if(id != ""){
                jQuery.ajax({
                    url: "/art/incr-rcount",
                    type: "POST",
                    data: {"id": id},
                    success: function(result) {
                        if(result != null && result.code == 200 && result.data == 1) {
                            console.log("文章阅读量自增成功！");
                        }else {
                            console.log("文章阅读量自增失败！");
                        }
                    }
                });
            }   
        }

        // 调用自增回调函数
        addRcount();
    </script> 
</body>

</html>